<template> 
  <div class="app-container">
    <el-card class="operate-container" shadow="never">
      <i class="el-icon-tickets" style="margin-top: 5px"></i>
      <span style="margin-top: 5px">数据列表</span>
      <el-button
        style="float: right"
        class="btn-add"
        @click="OpenAdd()"
        size="mini">
        添加
      </el-button>
    </el-card>

    <div class="table-container">
      <el-table  :data="arr" border style="width: 100%">
        <el-table-column  label="ID"  width="180">
          <template slot-scope="scope">
            <span style="margin-left: 10px" v-html="scope.row.id"></span>
          </template>
        </el-table-column>
        <el-table-column  label="商品属性分类名称"  width="180">
          <template slot-scope="scope">
            <span style="margin-left: 10px" v-html="scope.row.name"></span>
          </template>
        </el-table-column>
        <el-table-column  label="属性数量"  width="180">
          <template slot-scope="scope">
            <span style="margin-left: 10px" v-html="scope.row.attrcount"></span>
          </template>
        </el-table-column>
        <el-table-column  label="参数数量"  width="180">
          <template slot-scope="scope">
            <span style="margin-left: 10px" v-html="scope.row.paramscount"></span>
          </template>
        </el-table-column>
        <el-table-column label="设置" width="200" align="center">
          <template slot-scope="scope">
            <el-button
              size="mini"
              @click="getAttrList(scope.$index, scope.row)">属性列表
            </el-button>
            <el-button
              size="mini"
              @click="getParamList(scope.$index, scope.row)">参数列表
            </el-button>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              size="mini"
              @click="handleEdit(scope.row)">编辑</el-button>
            <el-button
              size="mini"
              type="danger"
              @click="handleDelete(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <div class="pagination-container">


      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="this.attributeCategoryDTO.pageNum"
        :page-sizes="[1, 2, 3, 4, 5]"
        :page-size="this.attributeCategoryDTO.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </div>
      <el-dialog title="添加" :visible.sync="dialogFormVisible">
        <el-form :model="attributeCategory">
          <el-form-item label="类型名称" :label-width="formLabelWidth">
            <el-input v-model="attributeCategory.name" autocomplete="off"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="doAdd">确 定</el-button>
        </div>
      </el-dialog>

      <el-dialog title="修改" :visible.sync="dialogFormVisible2">
        <el-form :model="attributeCategory">
          <el-form-item label="类型名称" :label-width="formLabelWidth">
            <el-input v-model="attributeCategory.name" autocomplete="off"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible2 = false">取 消</el-button>
          <el-button type="primary" @click="doUpdate">确 定</el-button>
        </div>
      </el-dialog>

  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）,
//例如：import 《组件名称》 from '《组件路径》,


import {
  addAttributeCategory,
  deleteAttributeCategory,
  findList,
  updateAttributeCategory
} from "@/api/product/attributeCategory";

export default {
  //import引入的组件需要注入到对象中才能使用"
  components: {},
  props: {},
  data() {
    //这里存放数据"

    return {
      formLabelWidth: '120px',
      total:0,
      attributeCategory:[],
      arr:[],
      attributeCategoryDTO:{
        pageNum:1,
        pageSize:3,
      },
      ids:{
        id:0
      }
    };
  },
  //计算属性 类似于data概念",
  computed: {

  },
  //监控data中的数据变化",
  watch: {},
  //方法集合",
  methods: {
    getAttrList(index, row) {
      console.log(row)
      this.$router.push({path: '/product/attribute',query:{cid:row.id,cname:row.name,type:0}})
    },
    getParamList(index, row) {
      this.$router.push({path: '/product/product/addProductAttribute',query:{cid:row.id,cname:row.name,type:1}})
    },
    // 删除
    handleDelete(id) {
      alert(id)
      console.log(this.row.id)
      this.ids.id=id
      deleteAttributeCategory(this.row.id).then(res => {
          this.$message.success(res.msg || "删除成功");
          this.ProductAttributeCategoryList();
        }
      ).catch(
        err => {
          this.$message.error(err.message || "删除失败");
        }
      );
    },
    // 修改
    doUpdate(){
      updateAttributeCategory(this.attributeCategory).then(
        res=>{
          this.$message.success(res.msg||"修改成功")
          this.dialogFormVisible2=false
          this.ProductAttributeCategoryList()
        }
      )
    },
    // 添加
    doAdd(){
      addAttributeCategory(this.attributeCategory).then(
        res=>{
          this.$message.success(res.msg||"添加成功")
          this.dialogFormVisible=false
          this.ProductAttributeCategoryList()
        }
      )
    },
    // 打开编辑窗口
    handleEdit(stu){
      this.dialogFormVisible2=true
      this.attributeCategory={}
      this.attributeCategory=stu

    },
    // 打开添加窗口
    OpenAdd(){
      this.dialogFormVisible=true
      this.attributeCategory={}
    },
    // 列表
    ProductAttributeCategoryList(){
      findList(this.attributeCategoryDTO).then(res=>{
          console.log(res)
          this.arr=res.data.list;
          this.total=res.data.total;
        }
      )
    },
    // 分页
    handleSizeChange(val) {
      this.attributeCategoryDTO.pageSize=val
      console.log(`每页 ${val} 条`);
      this.ProductAttributeCategoryList()
    },
    handleCurrentChange(val) {
      this.attributeCategoryDTO.pageNum=val
      console.log(`当前页: ${val}`);
      this.ProductAttributeCategoryList()
    }
  },
  //生命周期 - 创建完成（可以访问当前this实例）",
  created() {
    this.ProductAttributeCategoryList();
  },
  //生命周期 - 挂载完成（可以访问DOM元素）",
  mounted() {
  },
  beforeCreate() {
  }, //生命周期 - 创建之前",
  beforeMount() {
  }, //生命周期 - 挂载之前",
  beforeUpdate() {
  }, //生命周期 - 更新之前",
  updated() {
  }, //生命周期 - 更新之后",
  beforeDestroy() {
  }, //生命周期 - 销毁之前",
  destroyed() {
  }, //生命周期 - 销毁完成",
  activated() {
  } //如果页面有keep-alive缓存功能，这个函数会触发",
};
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
</style>
